#!/usr/bin/env python
#This file is used to define anything that will end up in a COP
#See parent classes for explanation of non-annotated properties

from constants import UnitRadarRanges
from google.appengine.ext import db

#Parent class for all objects in the COP
class __copObject(db.Model):
    #Folder in the COP
    folder = "COP Error Folder"

#Parent class for all units
class __Unit(__copObject):
    #No radar by default
    radarRange = 0
    #Default Unit Folder - Should never be used
    folder = "Unit Error Folder"
    #User that owns the unit
    owner = db.UserProperty(verbose_name="Owner", auto_current_user_add=True)
    #Location of the unit
    location = db.GeoPtProperty(verbose_name="Location", default=db.GeoPt(0,0))
    altitude = db.IntegerProperty(verbose_name="Altitude", default=0)
    #Radar hits
    radarHits = db.ListProperty(db.Key, verbose_name="Radar hits")

#Template for a building.  Should never be used directly
class __Building(__Unit):
    #Buildings don't have altitude
    altitude = 0
    #Default Building Folder
    folder = "Building Error Folder"

class Radar(__Building):
    radarRange = UnitRadarRanges.radarRange
    folder = "Radar Installations"


class Silo(__Building):
    radarRange = UnitRadarRanges.siloRange
    folder = "Nuclear Missile Silos"
    missiles = db.ListProperty(db.Key, verbose_name="Associated missiles")
    launchMode = db.BooleanProperty(verbose_name="Launch mode", default=False)
    lastLaunch = db.DateTimeProperty(verbose_name="Time of last launch", auto_now=True)

class Airbase(__Building):
    radarRange = UnitRadarRanges.airbaseRange
    folder = "Airbases"
    ISRAircraft = db.ListProperty(db.Key, verbose_name="ISR aircraft")
    bomberAircraft = db.ListProperty(db.Key, verbose_name="Bombers")

#Class to represent a hit on a radar
class RadarHit(__copObject):
    folder = "Radar Contacts"
    #Location of the emitter
    emitterLocation = db.GeoPtProperty(verbose_name="Emitter location", default=db.GeoPt(0,0))
    emitterAltitude = db.IntegerProperty(verbose_name="Emitter altitude", default=0)
    #Location of the collector
    collectorLocation = db.GeoPtProperty(verbose_name="Collector location", default=db.GeoPt(0,0))
    collectorAltitude = db.IntegerProperty(verbose_name="Collector altitude", default=0)
    #Time of hit
    time = db.DateTimeProperty(verbose_name="Hit time", auto_now_add=True)
    #Do we know the location of emitter?
    emitterLocationKnown = db.BooleanProperty(verbose_name="Emitter location known", default=False)

#Building Factory - Provides a nice mapping from string to a building type